from django import forms
from django.contrib.auth.forms import PasswordChangeForm

from userena.forms import (EditProfileForm, ChangeEmailForm, SignupForm
            , AuthenticationForm)
from userena.utils import get_profile_model, get_user_model
from image_cropping import ImageCropWidget

from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit

class ProfileForm(EditProfileForm):
    """ Extend EditProfileForm from userena.forms
        We need to use fields instead exclude
    """
    
    def __init__(self, *args, **kw):
        super(ProfileForm, self).__init__(*args, **kw)
        self.helper = FormHelper()
        self.helper.form_class = 'profile-form-edit'
        self.helper.form_id = 'profile_form'
        self.helper.add_input(Submit('submit', 'Submit'))

    class Meta:
        model = get_profile_model()
        fields = ['nick_name', 'privacy']


class AvatarForm(forms.ModelForm):
    """
    AvatarForm
    Display The avatar and let user to crop image.
    """
    def __init__(self, *args, **kw):
        super(AvatarForm, self).__init__(*args, **kw)
        self.helper = FormHelper()
        self.helper.form_id = 'cropping_form'
        self.helper.add_input(Submit('submit', 'Submit'))
        
    class Meta:
        model = get_profile_model()
        fields =['avatar', 'avatar_cropping']

class ProfilePasswordChangeForm(PasswordChangeForm):
    """
    ProfilePasswordChangeForm
    Change Profile Password Form
    """
    def __init__(self, *args, **kw):
        super(ProfilePasswordChangeForm, self).__init__(*args, **kw)
        self.helper = FormHelper()
        self.helper.form_class = 'profile-form-password'
        self.helper.add_input(Submit('submit', 'Submit'))

class ProfileChangeEmailForm(ChangeEmailForm):
    """
    ProfileChangeEmailForm
    Change Email Form
    """
    def __init__(self, *args, **kw):
        super(ProfileChangeEmailForm, self).__init__(*args, **kw)
        self.helper = FormHelper()
        self.helper.form_class = 'profile-form-email'
        self.helper.add_input(Submit('submit', 'Submit'))

class ProfileSignupForm(SignupForm):
    """
    Profile Signup Form
    Sign up Form
    """
    def __init__(self, *args, **kw):
        super(ProfileSignupForm, self).__init__(*args, **kw)
        self.helper = FormHelper()
        self.helper.form_class = 'profile-form-signup'
        self.helper.add_input(Submit('submit', 'Submit'))
        
class ProfileAuthenticationForm(AuthenticationForm):
    """
    Profile Signin Form
    Sign Form
    """
    def __init__(self, *args, **kw):
        super(ProfileAuthenticationForm, self).__init__(*args, **kw)
        self.helper = FormHelper()
        self.helper.form_class = 'profile-form-signin'
        self.helper.add_input(Submit('submit', 'Submit'))
    